//
//  TextDetailScorllView.m
//  Happy Kitchen
//
//  Created by dlios on 15/3/8.
//  Copyright (c) 2015年 mac_chen. All rights reserved.
//

#import "TextDetailScorllView.h"

@implementation TextDetailScorllView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSub];
    }
    return self;
}

- (void)createSub
{
    UILabel *describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 300, 30)];
    describeLabel.text = @"症状简介";
    describeLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:describeLabel];
    
    //症状简介label
    self.diseaseDescribeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, describeLabel.frame.origin.y + describeLabel.frame.size.height, 300, 1000)];
    CGRect diseaseFrame = self.diseaseDescribeLabel.frame;
    diseaseFrame.size.height = [[self class] heightFordiseaseDescribe:self.diseaseDescribeLabel.text];
    self.diseaseDescribeLabel.frame = diseaseFrame;
    self.diseaseDescribeLabel.numberOfLines = 0;
    [self addSubview:self.diseaseDescribeLabel];
    
    
    UILabel *eatLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.diseaseDescribeLabel.frame.origin.y + self.diseaseDescribeLabel.frame.size.height, 300, 30)];
    eatLabel.text = @"饮食保健";
    eatLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:eatLabel];
    
    
    //饮食保健label
    self.fitEatLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, eatLabel.frame.origin.y + eatLabel.frame.size.height , 300, 100)];
    CGRect fitEatFrame = self.fitEatLabel.frame;
    fitEatFrame.size.height = [[self class] heightForfitEat:self.fitEatLabel.text];
    self.fitEatLabel.frame = fitEatFrame;
    self.fitEatLabel.numberOfLines = 0;
    [self addSubview:self.fitEatLabel];
    
    
    UILabel *lifeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.fitEatLabel.frame.origin.y + self.fitEatLabel.frame.size.height , 300, 20)];
    lifeLabel.text = @"生活保健";
    lifeLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:lifeLabel];
    
    //生活保健label
    self.lifeSuitLabel = [[UILabel alloc] initWithFrame:CGRectMake(40,lifeLabel.frame.origin.y + lifeLabel.frame.size.height , 300, 100)];
    
    CGRect lifeFrame = self.lifeSuitLabel.frame;
    lifeFrame.size.height = [[self class] heightForlifeSuit:self.lifeSuitLabel.text];
    self.lifeSuitLabel.frame = lifeFrame;
    self.lifeSuitLabel.numberOfLines = 0;
    [self addSubview:self.lifeSuitLabel];
    
 
    
    self.contentSize = CGSizeMake(self.frame.size.width, self.diseaseDescribeLabel.frame.size.height +self.fitEatLabel.frame.size.height + self.lifeSuitLabel.frame.size.height + 250);
    
    
}

//赋值
- (void)setDiseaseDescribe:(NSString *)diseaseDescribe fitEat:(NSString *)fitEat lifeSuit:(NSString *)lifeSuit
{
    self.diseaseDescribeLabel.text = diseaseDescribe;
    self.fitEatLabel.text = fitEat;
    self.lifeSuitLabel.text = lifeSuit;
}

//自适应高度
+ (CGFloat)heightFordiseaseDescribe:(NSString *)text
{
    CGSize size = CGSizeMake(300, 1000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height + 230;
}

+ (CGFloat)heightForfitEat:(NSString *)text
{
    CGSize size = CGSizeMake(300, 1000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height + 150;
}

+ (CGFloat)heightForlifeSuit:(NSString *)text
{
    CGSize size = CGSizeMake(300, 1000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height + 150;
}

@end
